<template>
    <z-paging
        ref="paging"
        v-model="orderCouponList"
        :refresher-out-rate="0.8"
        auto-scroll-to-top-when-reload
        :auto-clean-list-when-reload="true"
        safe-area-inset-bottom
        bg-color="#fff"
    >
		<view class="enterprise_top">
		    <text class="enterprise_bg"></text>
		    <u-text text="仓库福鸡" size="32rpx" bold />
		</view>
        <view class="coupon">
            <view class="coupon_item">
                <view class="coupon_item_title flex_wrap row_middle">
                    <text class="coupon_item_title_orderNumberDisplay"></text>
                    <view class="coupon_item_title_halfCircle left" />
                    <view class="coupon_item_title_halfCircle right" />
                </view>
                <view class="coupon_item_content flex_wrap flex_column">
                    <view
                        class="coupon_item_content_num flex_wrap row_between-column_center"
                    >
                        <text v-if="shareBtnShow">福鸡数量：{{chickenInfo.chick_card_num || '0'}}</text>
                    </view>
                    <view
                        class="flex_wrap row_center-column_center"
                    >
                        <u--image
							v-if="shareBtnShow"
                            src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2024/01/19/403ea030d0d24b2b9abdeda452542f5b.png"
                            width="322rpx"
                            height="418rpx"
                        ></u--image>
						<u--image
							v-if="!shareBtnShow"
						    src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/987eadb1d50949a0a7e25dbbd99abe30.png"
						    width="308rpx"
						    height="308rpx"
						></u--image>
                    </view>
					<u-text v-if="!shareBtnShow" text="暂无福鸡~" size="28rpx" color="#777777" align="center"/>
                </view>
            </view>
            <u-button
				v-if="shareBtnShow"
                text="转送给好友"
				openType="share"
				:customStyle="btnStyle"
            ></u-button>
			<u-button
				v-if="!shareBtnShow"
			    text="转送给好友"
				:customStyle="noBtnStyle"
			></u-button>
            <view class="toList">
				<u-icon name="arrow-right" labelPos="left" labelColor="#588bf3" labelSize="32rpx" color="#588bf3" size="32rpx" space="22rpx" label="赠送记录" @click="to_list()"></u-icon>
            </view>
        </view>
    </z-paging>
</template>

<script>
import { mapGetters } from "vuex";
import caches from "@/config/caches.js";
import { chickUrl } from "@/config/tendIdConfig.js";
import { encryption } from "@/utils/encryption.js";
export default {
    data() {
        return {
            orderNum: "",
            codeSize: uni.upx2px(472),
            shareCanvasWidth: uni.upx2px(694),
            shareCanvasHeight: uni.upx2px(558),
            currentOrderDetailData: {},
            canvasWidth: 0,
            canvasHeight: 0,
            orderCouponList: [],
			btnStyle:{
				backgroundColor: '#1682FF',
				color: "#fff",
				borderRadius: '8rpx',
			},
			noBtnStyle:{
				backgroundColor: 'rgba(88,139,243,0.5)',
				color: "#fff",
				borderRadius: '8rpx',
			},
			token:'',
			chickenInfo:{},
			log_id:'',
			shareBtnShow:false
        };
    },
    onLoad(options) {
        this.orderNum = '20240108102639000154hqsd72'
		this.getChickenToken()
    },
    computed: {
        ...mapGetters(["userInfo"]),
    },

    methods: {
		to_list(){
			uni.$u.route({
			    url: "pages_chicken/list/index",
			    params: {
			        token: this.token
			    },
			});
		},
		getChickenToken() {
		    const phone = uni.getStorageSync(caches.PHONE);
			const userName = uni.getStorageSync(caches.USER_INFO)["nickName"] || uni.getStorageSync(caches.USER_INFO)["salesmanName"] || ''
			console.log( userName,'分享人userName>>>')
		    uni.request({
		        url: chickUrl + "/api/v1/auth/phone-login",
		        method: "POST",
		        data: {
		            ...encryption({
		                user_phone: phone,
						user_name: userName
		            }),
		        },
		        success: (res) => {
		            this.token = res.data.data.token;
					this.getMyChicken(phone)
		        },
		        fail: (err) => {
		            console.log(err, "22");
		        },
		    });
		},
		getMyChicken(phone) {
		    uni.request({
		        url:chickUrl + "/api/v1/open/chick/user-chick-property",
		        method: "GET",
		        data: {
					...encryption({
					    user_account: phone,
					}),
		        },
		        success: (res) => {
					console.log(res,'res??????')
					if(res.data.errcode == 200){
						this.chickenInfo = res.data.data
						if(this.chickenInfo.chick_card_num){
							this.shareBtnShow = true
						}
					}else{
						uni.$u.toast(res.data.errmsg)
					}
		        },
		        fail: (err) => {
		        },
		    });
		},
		onShareAppMessage(){
			return new Promise((resolve,reject)=>{
				const that = this;
				let path;
				uni.request({
				   url: chickUrl + '/api/v1/chick/transfer-out-chick',
				    method: "POST",
					data: {
					    type:6//仓库转赠福鸡卡'
					},
					header: {
						Authorization: `Bearer ${that.token}`,
					},
				    success(res) {
				        that.log_id = res.data.data.log_id
						path = '/pages_chicken/receive/index' + `?log_id=${that.log_id}` + `&fromshareIds=${that.userInfo.id}`
						console.log(that.log_id,'that.log_id>>>',path)
						resolve({
							title: "HI!我向您赠送了一只福鸡！快去领取吧~",
							path:path,
						})
				    },
				});
			})
		}
    },
};
</script>

<style lang="scss" scoped>
.enterprise_top {
    display: flex;
    height: 44rpx;
    align-items: center;
	padding: 28rpx;
}
.enterprise_bg {
    display: block;
    width: 8rpx;
    height: 28rpx;
    background: #588bf3;
    margin-right: 12rpx;
}
.toList{
	margin: 36rpx 0 64rpx;
}
.canvas {
    width: 694rpx;
    height: 558rpx;
    position: fixed;
    left: 1000px;
    top: 0;
}
.coupon_item_content_num {
    margin-bottom: 112rpx;
    padding: 0 46rpx;
    font-size: 28rpx;
    color: #333333;
    font-weight: bold;
}
.coupon_item_content_Buttons {
    width: 100%;
    margin-top: 86rpx;
}
.coupon {
    padding: 0 28rpx;
    box-sizing: border-box;

    &_item {
        width: 694rpx;
        box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.12);
        border-radius: 12rpx;
        margin-top: 28rpx;

        &_content {
            width: 100%;
            padding: 60rpx;
            box-sizing: border-box;
        }

        &_title {
            padding: 0 40rpx;
            height: 76rpx;
            border-bottom: 1px dashed rgba(51, 51, 51, 0.5);
            position: relative;
            &_orderNumberDisplay {
                font-size: 30rpx;
                color: #333;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            &_orderNumberDisplay.disable {
                text-decoration: line-through;
                color: #999999 !important;
            }

            &_status {
                font-size: 26rpx;
                color: #588bf3;
                font-weight: bold;
            }

            &_status.disable {
                color: #999999 !important;
            }

            &_halfCircle {
                width: 18rpx;
                height: 24rpx;
                background-color: #ededed;
                position: absolute;
            }

            &_halfCircle.left {
                border-top-right-radius: 50px;
                border-bottom-right-radius: 50px;
                left: 0;
                bottom: -12rpx;
            }

            &_halfCircle.right {
                border-top-left-radius: 50px;
                border-bottom-left-radius: 50px;
                right: 0;
                bottom: -12rpx;
            }
        }
    }
}
</style>
